//
//  CarLogTableViewCell.m
//  Rail
//
//  Created by hychen on 2018/3/4.
//  Copyright © 2018年 Hychen. All rights reserved.
//

#import "CarLogTableViewCell.h"

@interface CarLogTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *carNumLabel;
@property (weak, nonatomic) IBOutlet UIButton *ownerLabel;
@property (weak, nonatomic) IBOutlet UIButton *statusLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;

@end
@implementation CarLogTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self showBottomLineWithPaddingX:15 color:nil];
    
    [self showArrowWithImage:nil];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void)setCarLogStatus:(BOOL)isIn {
    if (isIn) {
        [self.statusLabel setTitle:@"已进岗" forState:UIControlStateNormal];
        [self.statusLabel setTitleColor:Color_RGB(255, 50, 64) forState:UIControlStateNormal];
        NSString *image = [self.model.in_img1 objectIsNotEmpty]?self.model.in_img1:[self.model.out_img1 objectIsNotEmpty]?self.model.out_img1:@"";
        [self.iconView sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:ImageNamed_bb(@"app_picture_default_img") options:SDWebImageAllowInvalidSSLCertificates|SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            if (error) {
                NSLog(@"请求图片错误:%@",error.localizedDescription);
            }
        }];
        self.timeLabel.text = [BMUtils chineseMMDDHHmmWithServiceTime:self.model.in_time];
    }
    else {
        [self.statusLabel setTitle:@"已出岗" forState:UIControlStateNormal];
        [self.statusLabel setTitleColor:Color_RGB(0, 193, 224) forState:UIControlStateNormal];
        NSString *image = [self.model.out_img1 objectIsNotEmpty]?self.model.out_img1:[self.model.in_img1 objectIsNotEmpty]?self.model.in_img1:@"";
        [self.iconView sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:ImageNamed_bb(@"app_picture_default_img") options:SDWebImageAllowInvalidSSLCertificates|SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            if (error) {
                NSLog(@"请求图片错误:%@",error.localizedDescription);
            }
        }];
        self.timeLabel.text = [BMUtils chineseMMDDHHmmWithServiceTime:self.model.out_time];
    }
}

- (void)setModel:(CarAccessModel *)model {
    _model = model;
    self.carNumLabel.text = model.plate_num;
    [self.ownerLabel setTitle:model.driver_name forState:UIControlStateNormal];
    self.ownerLabel.userInteractionEnabled = NO;
    [self setCarLogStatus:model.status == CarLogTypeLogIn?YES:NO];
}
@end
